package ReefStats::Schema::ReefStatsDB::Users;

use warnings;
use strict;
use base 'DBIx::Class';
use ReefStats::Schema::DataTypes;

__PACKAGE__->load_components(qw/InflateColumn::DateTime Core/);
__PACKAGE__->table('users_');
__PACKAGE__->add_columns(
    id                               => { @_int_id, },
    email_address                    => { @_varchar_255, @_not_null, },
    password                         => { @_varchar_255, @_not_null, },
    domain_id                        => { @_int, extra => { @_unsigned, } },
    password_reset_token             => { @_varchar_255, },
    password_reset_request_timestamp => { @_datetime, },
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->add_unique_constraint( ['email_address'] );
__PACKAGE__->has_many(
    map_user_role => 'ReefStats::Schema::ReefStatsDB::UserRoles',
    => 'user_id',
    { cascade_delete => 0 }
);
__PACKAGE__->many_to_many( roles => 'map_user_role', 'role' );
__PACKAGE__->might_have(
    domain => 'ReefStats::Schema::ReefStatsDB::Domains',
    { 'foreign.id' => 'self.domain_id' }, { cascade_delete => 0 }
);

#__PACKAGE__->many_to_many(
#    'application_user_roles' => 'applications_users_user_roles',
#    'applicaiton_user_role',
#    { cascade_delete => 0 },
#);

1;

__END__
